package com.neuedu.dao.impl;

import com.neuedu.common.DBUtil;
import com.neuedu.dao.BaseDao;
import com.neuedu.dao.DeptTypeDao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class DeptTypeDaoImpl extends BaseDao implements DeptTypeDao {

    @Override
    public List<Map<String, Object>> getAllDeptType(String sql) {
        Connection con = DBUtil.getCon();
        return this.querySql(con, sql);
    }

    @Override
    public int delclassify(Object[] objs) {
        String sql = "DELETE FROM depttype WHERE id=?";
        String sql1 = "DELETE FROM deptment WHERE depttypeid=?";
        Connection con = DBUtil.getCon();
        int flag = 0;
        int flag1 = 0;
        try {
            flag = this.delUpins(sql, objs, con);
            System.out.println(flag);
            flag1 = this.delUpins(sql1, objs, con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    @Override
    public int addClassify(Object[] objs) {
        String sql = "INSERT INTO depttype VALUES(?,?)";
        Connection con = DBUtil.getCon();
        int flag = 0;
        try {
            flag = this.delUpins(sql, objs, con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    @Override
    public int updateClassify(Object[] objs) {
        String sql = "UPDATE depttype SET typename=? WHERE id=?";
        Connection con = DBUtil.getCon();
        int flag = 0;
        try {
            flag = this.delUpins(sql, objs, con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    @Override
    public List<Map<String, Object>> getLikeDeptClassity(String sql, Object[] objs) {
        Connection con = DBUtil.getCon();
        List<Map<String, Object>> list = null;
        try {
            list = this.queryParmSqlAsName(sql, objs, con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }
}
